home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / scissor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-13  |  2.8 KB  |  112 lines

  1. /* $Id: scissor.c,v 1.2 1996/09/15 14:18:37 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.0
  6.  * Copyright (C) 1995-1996  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: scissor.c,v $
  26.  * Revision 1.2  1996/09/15 14:18:37  brianp
  27.  * now use GLframebuffer and GLvisual
  28.  *
  29.  * Revision 1.1  1996/09/13 01:38:16  brianp
  30.  * Initial revision
  31.  *
  32.  */
  33.  
  34.  
  35. #include "context.h"
  36. #include "macros.h"
  37. #include "dlist.h"
  38. #include "scissor.h"
  39. #include "types.h"
  40.  
  41.  
  42.  
  43. void gl_Scissor( GLcontext *ctx,
  44.                  GLint x, GLint y, GLsizei width, GLsizei height )
  45. {
  46.    if (width<0 || height<0) {
  47.       gl_error( ctx, GL_INVALID_VALUE, "glScissor" );
  48.       return;
  49.    }
  50.    if (INSIDE_BEGIN_END(ctx)) {
  51.       gl_error( ctx, GL_INVALID_OPERATION, "glBegin" );
  52.       return;
  53.    }
  54.  
  55.    ctx->Scissor.X = x;
  56.    ctx->Scissor.Y = y;
  57.    ctx->Scissor.Width = width;
  58.    ctx->Scissor.Height = height;
  59.  
  60.    ctx->NewState |= NEW_ALL;  /* TODO: this is overkill */
  61. }
  62.  
  63.  
  64.  
  65. /*
  66.  * Apply the scissor test to a span of pixels.
  67.  * Return:  0 = all pixels in the span are outside the scissor box.
  68.  *          1 = one or more pixels passed the scissor test.
  69.  */
  70. GLint gl_scissor_span( GLcontext *ctx,
  71.                        GLuint n, GLint x, GLint y, GLubyte mask[] )
  72. {
  73.    /* first check if whole span is outside the scissor box */
  74.    if (y<ctx->Buffer->Ymin || y>ctx->Buffer->Ymax
  75.        || x>ctx->Buffer->Xmax || x+(GLint)n-1<ctx->Buffer->Xmin) {
  76.       return 0;
  77.    }
  78.    else {
  79.       GLuint i;
  80.       /* TODO: this could be better: */
  81.       for (i=0;i<n;i++,x++) {
  82.      if (x<ctx->Buffer->Xmin || x>ctx->Buffer->Xmax)
  83.        mask[i] = 0;
  84.       }
  85.       return 1;
  86.    }
  87. }
  88.  
  89.  
  90.  
  91.  
  92. /*
  93.  * Apply the scissor test to an array of pixels.
  94.  */
  95. GLuint gl_scissor_pixels( GLcontext *ctx,
  96.                           GLuint n, const GLint x[], const GLint y[],
  97.                           GLubyte mask[] )
  98. {
  99.    GLint xmin = ctx->Buffer->Xmin;
  100.    GLint xmax = ctx->Buffer->Xmax;
  101.    GLint ymin = ctx->Buffer->Ymin;
  102.    GLint ymax = ctx->Buffer->Ymax;
  103.    GLuint i;
  104.  
  105.    for (i=0;i<n;i++) {
  106.       mask[i] &= (x[i]>=xmin) & (x[i]<=xmax) & (y[i]>=ymin) & (y[i]<=ymax);
  107.    }
  108.  
  109.    return 1;
  110. }
  111.  
  112.